home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / gui / uberwidgets / PrefPanel.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  9KB  |  263 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import wx
  5. from gui.uberwidgets.UberButton import UberButton
  6. from gui.uberwidgets.UberCombo import UberCombo
  7. from gui.uberwidgets.simplemenu import SimpleMenuItem
  8. from gui.skin.skinparse import makeFont
  9. from cgui import SimplePanel
  10. from gui.anylists import AnyList
  11. from gui.toolbox import AutoDC
  12. from wx import BoxSizer, BOTTOM, TOP, LEFT, RIGHT, EXPAND, VERTICAL, HORIZONTAL
  13. wxMac = 'wxMac' in wx.PlatformInfo
  14.  
  15. def PrefCollection(*workers, **options):
  16.     if 'layout' in options:
  17.         layout = options['layout']
  18.     else:
  19.         layout = wx.GridSizer(cols = 1)
  20.     if 'itemoptions' in options:
  21.         itemoptions = options['itemoptions']
  22.     else:
  23.         itemoptions = (0, EXPAND)
  24.     
  25.     def Factory(parent, prefix = (None, None, '')):
  26.         panel = wx.Panel(parent, style = wx.FULL_REPAINT_ON_RESIZE)
  27.         panel.Sizer = layout
  28.         for workerortuple in workers:
  29.             if isinstance(workerortuple, tuple):
  30.                 worker = workerortuple[0]
  31.                 addoptions = workerortuple[1:]
  32.             else:
  33.                 worker = workerortuple
  34.                 addoptions = None
  35.             if callable(worker):
  36.                 window = worker(panel, prefix)
  37.             elif isinstance(worker, wx.WindowClass):
  38.                 window = worker
  39.                 window.Reparent(panel)
  40.             
  41.             if not addoptions:
  42.                 pass
  43.             panel.Sizer.Add(window, *itemoptions)
  44.         
  45.         return panel
  46.  
  47.     return Factory
  48.  
  49. pref_sizer_style = EXPAND | LEFT | RIGHT | BOTTOM
  50. combo_sizer_flags = (LEFT | RIGHT, 7)
  51. if wxMac:
  52.     header_sizer_flags = (wx.ALIGN_BOTTOM,)
  53.     space_over_header = 3
  54.     space_under_header = 8
  55. else:
  56.     header_sizer_flags = (LEFT | wx.ALIGN_CENTER_VERTICAL, 7)
  57.     space_over_header = 0
  58.     space_under_header = 5
  59.  
  60. class PrefPanel(SimplePanel):
  61.     
  62.     def __init__(self, parent, content = None, title = '', buttonlabel = '', buttoncb = None, titlemaker = None, prefix = ''):
  63.         SimplePanel.__init__(self, parent, wx.FULL_REPAINT_ON_RESIZE)
  64.         sizer = self.Sizer = BoxSizer(VERTICAL)
  65.         self.headersizer = BoxSizer(HORIZONTAL)
  66.         self.bodysizer = BoxSizer(VERTICAL)
  67.         sizer.Add(self.headersizer, 0, EXPAND | TOP, space_over_header)
  68.         sizer.Add(self.bodysizer, 1, EXPAND | TOP, space_under_header)
  69.         self.title = None
  70.         self.combo = None
  71.         self.button = None
  72.         self.content = None
  73.         self.contents = { }
  74.         self.titlemaker = titlemaker
  75.         if title and isinstance(title, basestring):
  76.             self.title = wx.StaticText(self, -1, ' ' + title + ' ', style = wx.ALIGN_CENTER_VERTICAL)
  77.             if wxMac:
  78.                 self.title.BackgroundColour = wx.Color(232, 232, 232)
  79.             
  80.             self.title.Font = self.HeaderFont
  81.             self.headersizer.Add(self.title, 0, *header_sizer_flags)
  82.         
  83.         if callable(content):
  84.             content = self.content = content(self, prefix)
  85.             self.bodysizer.Add(self.content, 1, pref_sizer_style, 7)
  86.         elif isinstance(content, wx.WindowClass):
  87.             content.Reparent(self)
  88.             self.content = content
  89.             self.bodysizer.Add(self.content, 1, pref_sizer_style, 7)
  90.         elif isinstance(content, list):
  91.             self.SetContents(content)
  92.         
  93.         if buttoncb:
  94.             self.SetButton(buttonlabel, buttoncb)
  95.         
  96.         Bind = self.Bind
  97.         Bind(wx.EVT_PAINT, self.OnPaint)
  98.         if not wxMac:
  99.             self.pen = wx.Pen(wx.Colour(213, 213, 213))
  100.         else:
  101.             self.pen = wx.Pen(wx.Colour(155, 155, 155))
  102.  
  103.     
  104.     def HeaderFont(self):
  105.         
  106.         try:
  107.             return self._headerfont
  108.         except AttributeError:
  109.             if not wxMac:
  110.                 PrefPanel._headerfont = makeFont('arial 8 bold')
  111.             else:
  112.                 PrefPanel._headerfont = makeFont('9 bold')
  113.             return self._headerfont
  114.  
  115.  
  116.     HeaderFont = property(HeaderFont)
  117.     _fg_brush = _bg_brush = _fg_pen = _bg_pen = (lambda self: pass)
  118.     
  119.     def get_bg_brush(self):
  120.         if not self._bg_brush():
  121.             pass
  122.         return wx.WHITE_BRUSH
  123.  
  124.     
  125.     def get_fg_brush(self):
  126.         if not self._fg_brush():
  127.             pass
  128.         return wx.TRANSPARENT_BRUSH
  129.  
  130.     
  131.     def get_bg_pen(self):
  132.         if not self._bg_pen():
  133.             pass
  134.         return wx.TRANSPARENT_PEN
  135.  
  136.     
  137.     def get_fg_pen(self):
  138.         if not self._fg_pen():
  139.             pass
  140.         return self.pen
  141.  
  142.     bg_brush = property(get_bg_brush)
  143.     fg_brush = property(get_fg_brush)
  144.     bg_pen = property(get_bg_pen)
  145.     fg_pen = property(get_fg_pen)
  146.     
  147.     def OnPaint(self, event):
  148.         size = self.Size
  149.         dc = AutoDC(self)
  150.         if not wxMac:
  151.             rect = wx.RectS(size)
  152.             dc.Brush = self.bg_brush
  153.             dc.Pen = self.bg_pen
  154.             dc.DrawRectangleRect(rect)
  155.             ypos = self.headersizer.Size.height // 2 + space_over_header
  156.             gc = wx.GraphicsContext.Create(dc)
  157.             gc.SetBrush(self.fg_brush)
  158.             gc.SetPen(self.fg_pen)
  159.             gc.DrawRoundedRectangle(0, ypos, size.width - 1, size.height - ypos - 1, 5)
  160.         else:
  161.             ypos = self.headersizer.Size.height // 2 + space_over_header + 2
  162.             dc.Pen = self.fg_pen
  163.             button_width = None if self.button is None else self.button.Size.width
  164.             dc.DrawLine(10, ypos, self.headersizer.Size.width - 10 - button_width, ypos)
  165.         content = self.content
  166.         if isinstance(content, AnyList):
  167.             crect = wx.Rect(*content.Rect)
  168.             crect = crect.Inflate(1, 1)
  169.             dc.SetBrush(wx.TRANSPARENT_BRUSH)
  170.             dc.SetPen(self.pen)
  171.             dc.DrawRectangleRect(crect)
  172.         
  173.  
  174.     
  175.     def ChangeShownContent(self, *a):
  176.         if self.content:
  177.             self.content.Show(False)
  178.         
  179.         if wxMac:
  180.             menu_item = self.combo.GetClientData(self.combo.GetSelection())
  181.         else:
  182.             menu_item = self.combo.Value
  183.         self.content = self.contents[menu_item]
  184.         self.content.Show(True)
  185.         self.Layout()
  186.  
  187.     
  188.     def SetButton(self, label, callback):
  189.         if self.button:
  190.             self.headersizer.Detach(self.button)
  191.             self.button.Destroy()
  192.         
  193.         if not wxMac:
  194.             self.button = UberButton(self, -1, label, skin = 'AppDefaults.PrefButton')
  195.         else:
  196.             self.button = wx.Button(self, -1, label)
  197.             self.button.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)
  198.         None((self.button.Bind, wx.EVT_BUTTON), (lambda e: callback(self.button)))
  199.         self.headersizer.AddStretchSpacer(1)
  200.         self.headersizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL | RIGHT, 7)
  201.  
  202.     
  203.     def MenuItems(self):
  204.         combo = self.combo
  205.  
  206.     MenuItems = property(MenuItems)
  207.     
  208.     def SetContents(self, content, destroyold = False):
  209.         if destroyold:
  210.             if not self.contents:
  211.                 self.content.Destroy()
  212.             
  213.             for content in self.contents.values():
  214.                 content.Destroy()
  215.             
  216.         
  217.         if self.content:
  218.             self.content.Show(False)
  219.             self.content = None
  220.         
  221.         self.bodysizer.Clear()
  222.         contents = self.contents = { }
  223.         titlemaker = self.titlemaker
  224.         if self.combo is None:
  225.             if not wxMac:
  226.                 self.combo = UberCombo(self, value = '', skinkey = 'AppDefaults.PrefCombo', valuecallback = self.ChangeShownContent)
  227.             else:
  228.                 self.combo = wx.ComboBox(self, style = wx.CB_DROPDOWN | wx.CB_READONLY)
  229.                 self.combo.Bind(wx.EVT_COMBOBOX, self.ChangeShownContent)
  230.             newcombo = True
  231.         else:
  232.             self.combo.RemoveAllItems()
  233.             newcombo = False
  234.         for object in content:
  235.             if isinstance(object, tuple):
  236.                 (window, label) = object
  237.             elif isinstance(object, wx.WindowClass):
  238.                 window = object
  239.                 label = None if titlemaker else object.Label
  240.             
  241.             window.Show(False)
  242.             window.Reparent(self)
  243.             self.bodysizer.Add(window, 1, pref_sizer_style, 7)
  244.             menuitem = SimpleMenuItem(label)
  245.             contents[menuitem] = window
  246.             if wxMac:
  247.                 self.combo.Append(menuitem.GetContentAsString(), menuitem)
  248.                 continue
  249.             self.combo.AppendItem(menuitem)
  250.         
  251.         if self.combo:
  252.             if wxMac:
  253.                 self.combo.SetSelection(0)
  254.                 self.ChangeShownContent()
  255.             else:
  256.                 self.combo.Value = self.combo[0]
  257.         
  258.         if self.combo is not None and newcombo:
  259.             self.headersizer.Add(self.combo, 1, *combo_sizer_flags)
  260.         
  261.  
  262.  
  263.